package com.drojian.demo2.fragement;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.drojian.demo.R;


public class BlankFragment1 extends Fragment implements View.OnClickListener{
    private View view;
    private TextView textView;


    private MyFragmentCallBack myFragmentCallBack;
    public MyFragmentCallBack getMyFragmentCallBack() {
        return myFragmentCallBack;
    }

    public void setMyFragmentCallBack(MyFragmentCallBack myFragmentCallBack) {
        this.myFragmentCallBack = myFragmentCallBack;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if(view == null){
            view = inflater.inflate(R.layout.part2_fragment_blank1, container, false);
        }
        textView = view.findViewById(R.id.textView1);
        Button button = view.findViewById(R.id.button1);
        button.setOnClickListener(this);
        Button sendMsgFromFragment = view.findViewById(R.id.button2);
        sendMsgFromFragment.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button1 :
                Bundle bundle = getArguments();
                String message = bundle.getString("message");
                textView.setText(message);
                break;
            case R.id.button2 :
                myFragmentCallBack.sendMsgToActivity("我来自fragment");
                break;
        }
    }
}